package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ILegalConfigSettingService;
import com.mdd.admin.validate.LegalConfigSettingCreateValidate;
import com.mdd.admin.validate.LegalConfigSettingSaveValidate;
import com.mdd.admin.validate.LegalConfigSettingSearchValidate;
import com.mdd.admin.validate.LegalConfigSettingUpdateValidate;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.LegalConfigSettingDetailVo;
import com.mdd.admin.vo.LegalConfigSettingListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("api/setting")
@Api(tags = "基础配置管理")
public class LegalConfigSettingController {

    @Resource
    ILegalConfigSettingService iLegalConfigSettingService;

    @GetMapping("/list")
    @ApiOperation(value="基础配置列表")
    public AjaxResult<PageResult<LegalConfigSettingListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated LegalConfigSettingSearchValidate searchValidate) {
        PageResult<LegalConfigSettingListedVo> list = iLegalConfigSettingService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/list2/{type}")
    @ApiOperation(value="基础配置列表")
    public AjaxResult<Map<String, Object>> list2(@PathVariable(value = "type") Integer type) {
        Map<String, Object> map = iLegalConfigSettingService.list2(type);
        return AjaxResult.success(map);
    }

    @GetMapping("/detail")
    @ApiOperation(value="基础配置详情")
    public AjaxResult<LegalConfigSettingDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LegalConfigSettingDetailVo detail = iLegalConfigSettingService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "基础配置新增")
    @PostMapping("/add")
    @ApiOperation(value="基础配置新增")
    public AjaxResult<Object> add(@Validated @RequestBody LegalConfigSettingCreateValidate createValidate) {
        iLegalConfigSettingService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "基础配置编辑")
    @PostMapping("/edit")
    @ApiOperation(value="基础配置编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody LegalConfigSettingUpdateValidate updateValidate) {
        iLegalConfigSettingService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "基础配置编辑")
    @PostMapping("/saveSetting")
    @ApiOperation(value="基础配置编辑")
    public AjaxResult<Object> saveSetting(@Validated @RequestBody LegalConfigSettingSaveValidate updateValidate) {
        iLegalConfigSettingService.saveSetting(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "基础配置删除")
    @PostMapping("/del")
    @ApiOperation(value="基础配置删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iLegalConfigSettingService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
